"use strict";
const defaultMaxRetries = 3;

const retryWithPromise = function(getPromise, maxRetries) {
	maxRetries = maxRetries || defaultMaxRetries;
	let promise = getPromise();
	let i = 0;
	const retry = function(e) {
		console.error(`promise失败，剩余的重试次数是${maxRetries - i + 1} `, e);
		return getPromise();
	};
	for (; i < maxRetries; i++) {
		promise = promise.then(data => data, retry);
	}
	return promise;
};
module.exports = {
	retryWithPromise
};